/**
 * Created by guodong on 2017/7/21.
 */
'use strict';
angular.module('app')
    .controller('platformSetController', [ '$rootScope', '$scope', '$http', '$state','$timeout',
        function($rootScope, $scope, $http, $state, $timeout) {
            $scope.title = '平台设置';
            $scope.searchParams = { };
            $scope.loading = false;
            $scope.param={};
            $scope.search = function () {
                $scope.loading = true;
                $.ajax({
                    url : $scope.app.project_name+'/platforms/sets/list',
                    data: $scope.searchParams
                }).then(function(result) {
                    console.log(result);
                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $(result.data.records).each(function () {
                            if(this.enable==='N'){
                                this.switchenable = true;
                            }else {
                                this.switchenable = false;
                            }
                        });
                        console.log(result.data.records);
                        $scope.pageInfo = result.data;

                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }

            $scope.search();

            $scope.searchRe = function () {
                $scope.loading = true;
                $scope.searchParams.pageNum = 1;
                $.ajax({
                    url : $scope.app.project_name+'/platforms/sets/list',
                    data: $scope.searchParams
                }).then(function(result) {

                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;
                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }

            $scope.clearSearch = function() {

                $scope.searchParams= { };
                $scope.search();
            }

            // if($('#enable').val()=='N'){
            //     $scope.alertModal({'content':'当前状态不能修改'});
            //     return;
            // }

            // 翻页
            $scope.pagination = function (pageNo) {
                $scope.searchParams.pageNum=pageNo;
                $scope.search();
            };

            $scope.oper = function (channelNo,$event) {

                $.ajax({
                    url : $scope.app.project_name+'/platforms/sets/banEnable',
                    data: {channelNo:channelNo,enable:$event.target.checked?'Y':'N'}
                }).then(function(result) {
                    $scope.loading = false;
                    if(!$event.target.checked){
                        $($event.target).parent().parent().siblings().find('input').each(function () {
                            this.disabled = true;
                        })
                    }
                    $scope.alertModal({"content":"操作成功"});
                    if (result.httpCode != 200) {
                        $scope.alertModal(result.msg);
                    }
                    $scope.search();
                });
            }

            $scope.oper1 = function (channelNo,$event) {

                $.ajax({
                    url : $scope.app.project_name+'/platforms/sets/banEnable',
                    data: {channelNo:channelNo,personIconSwitch:$event.target.checked?'Y':'N'}
                }).then(function(result) {
                    $scope.loading = false;
                    $scope.alertModal({"content":"操作成功"});
                    if (result.httpCode != 200) {
                        $scope.alertModal(result.msg);
                    }
                    $scope.search();
                });
            }

            $scope.oper2 = function (channelNo,$event) {

                $.ajax({
                    url : $scope.app.project_name+'/platforms/sets/banEnable',
                    data: {channelNo:channelNo,addIconSwitch:$event.target.checked?'Y':'N'}
                }).then(function(result) {
                    $scope.loading = false;
                    $scope.alertModal({"content":"操作成功"});
                    if (result.httpCode != 200) {
                        $scope.alertModal(result.msg);
                    }
                    $scope.search();
                });
            }

            $scope.oper3 = function (channelNo,$event) {

                $.ajax({
                    url : $scope.app.project_name+'/platforms/sets/banEnable',
                    data: {channelNo:channelNo,needImageFlag:$event.target.checked?'Y':'N'}
                }).then(function(result) {
                    $scope.loading = false;
                    $scope.alertModal({"content":"操作成功"});
                    if (result.httpCode != 200) {
                        $scope.alertModal(result.msg);
                    }
                    $scope.search();
                });
            }

            $scope.oper4 = function (channelNo,$event) {

                $.ajax({
                    url : $scope.app.project_name+'/platforms/sets/banEnable',
                    data: {channelNo:channelNo,needAuthFlag:$event.target.checked?'Y':'N'}
                }).then(function(result) {
                    $scope.loading = false;
                    $scope.alertModal({"content":"操作成功"});
                    if (result.httpCode != 200) {
                        $scope.alertModal(result.msg);
                    }
                    $scope.search();
                });
            }

            $scope.oper5 = function (channelNo,$event) {

                $.ajax({
                    url : $scope.app.project_name+'/platforms/sets/banEnable',
                    data: {channelNo:channelNo,needThirdFlag:$event.target.checked?'Y':'N'}
                }).then(function(result) {
                    $scope.loading = false;
                    $scope.alertModal({"content":"操作成功"});
                    if (result.httpCode != 200) {
                        $scope.alertModal(result.msg);
                    }
                    $scope.search();
                });
            }

            $scope.oper6 = function (channelNo,$event) {

                $.ajax({
                    url : $scope.app.project_name+'/platforms/sets/banEnable',
                    data: {channelNo:channelNo,hyzShowFlag:$event.target.checked?'Y':'N'}
                }).then(function(result) {
                    $scope.loading = false;
                    $scope.alertModal({"content":"操作成功"});
                    if (result.httpCode != 200) {
                        $scope.alertModal(result.msg);
                    }
                    $scope.search();
                });
            }
            // 是否显示授权页
            $scope.oper7 = function (channelNo,$event) {
                $.ajax({
                    url : $scope.app.project_name+'/platforms/sets/banEnable',
                    data: {channelNo:channelNo,grantFlag:$event.target.checked?'Y':'N'}
                }).then(function(result) {
                    $scope.loading = false;
                    $scope.alertModal({"content":"操作成功"});
                    if (result.httpCode != 200) {
                        $scope.alertModal(result.msg);
                    }
                    $scope.search();
                });
            }

        } ]);